# Check that libFuzzer honors SIGUSR1/SIGUSR2
# FIXME: Disabled on Windows for now because of reliance on posix only features
# (eg: export, "&", pkill).
UNSUPPORTED: darwin, target={{.*windows.*}}
RUN: rm -rf %t
RUN: mkdir -p %t
RUN: %cpp_compiler %S/SleepOneSecondTest.cpp -o %t/LFSIGUSR

RUN: mkdir -p %t/C1 %t/C2
RUN: echo a > %t/C2/a
RUN: echo b > %t/C2/b
RUN: echo c > %t/C2/c
RUN: echo d > %t/C2/d
RUN: echo e > %t/C2/e
RUN: echo f > %t/C2/f
RUN: echo g > %t/C2/g
RUN: echo h > %t/C2/g
RUN: echo i > %t/C2/g
RUN: echo j > %t/C2/g
RUN: echo k > %t/C2/g
RUN: echo l > %t/C2/g
RUN: echo m > %t/C2/g
RUN: echo n > %t/C2/g
RUN: echo o > %t/C2/g

# Run in new session so we can easily kill child processes all at once.
RUN: setsid %run %t/LFSIGUSR -merge=1 -merge_control_file=%t/MCF %t/C1 %t/C2 2>%t/log & export PID=$!
RUN: sleep 3
RUN: kill -SIGUSR2 -$(ps -o sess= $PID | grep -o '[0-9]*')
RUN: wait $PID || true
RUN: sleep 3
RUN: cat %t/log | FileCheck %s --dump-input=fail
RUN: grep C2/g %t/MCF
RUN: grep STARTED %t/MCF
RUN: tail -n 2 %t/MCF | grep FT
RUN: tail -n 1 %t/MCF | grep COV

CHECK: INFO: signal received, trying to exit gracefully
CHECK: INFO: libFuzzer: exiting as requested
